#pragma once
#include "NetNodeMgr.h"
#include "NetNodeSerializer.h"
#include "ViewTree.h"
#include <map>
using std::map;
#include <string>
using std::string;
#include "resource.h"

class NetNodeUIMgr
{
public:
	NetNodeUIMgr(void);
	~NetNodeUIMgr(void);
	NetNode * AddNetNode( NetNode& node );
	void EditNetNode( NetNode * nd, NetNode& newval );
	void EditBoard( Board* bd );
	void DelNetNode( NetNode* node );
	void DelBoard( NetNode * parent, CPoint pt );
	Board * AddBoard( Board& board, NetNode * parent, CPoint pt );
	int GetBoardPos( NetNode * parent, CPoint pt );
	void AddNetNodeToTree(NetNode * nd );
	void AddBoardToTree( Board * bd, NetNode * parent, int n );
	void DelBoardFromTree( Board * bd );
	void DelNetNodeFromTree( NetNode * bd );
	void init( CViewTree * tree );
	void DrawNode(NetNode *node, CDC* pDC, CRect& rect);
	void DrawBoard( Board * board, int slot, CRect& net_node_rect, CDC * pDC );
	void DrawLed( LED_STATE state, int led, CRect& board_rect, CDC * pDC );
	static string get_board_type_name( int id );
	static int get_board_type_pic( int id );
	bool in_board_range( CPoint pt, NetNode * nd );
	void clear(){ m_serializer.clear(); }
	void update_state();
private:
	NetNodeMgr m_nodemgr;
	NetNodeSerializer m_serializer;
	CViewTree * m_pTree;
	map<NetNode *, HTREEITEM > m_node2tree;
	map<Board *, HTREEITEM > m_board2tree;
	map<NetNode *, CRect > m_node2Rect;
};
